<template>
  <div>
    <f-table ref="table" rowKey="paymentId" :columns="columns" :multiple="false" :operator="operator"
             :params="queryParam" :api="api.payment" handler="sbReturnPaymentPageListHandler">
        <span slot="paymentState" slot-scope="text, record, index">
            <a-tag color="#87d068" v-if="text==0">未提交</a-tag>
             <a-tag color="#87d068" v-if="text==1" @click="processImg(record)">{{record.taskName}}</a-tag>
        </span>
      <span slot="action" slot-scope="text, record">
          <template>
            <a @click="startProcess(record)" v-if="record.paymentState==0">提交审批</a>
            <a @click="completeTask(record)" v-if="record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__'">提交审批</a>
            <a-divider type="vertical"
                       v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')"/>
            <a @click="$refs.drawer.showDrawer(record,'form2')">查看</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
               <a-menu-item v-if="record.paymentState==1">
                <a href="javascript:;" @click="processImg(record)">审批进度</a>
              </a-menu-item>
              <a-menu-item
                v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')">
                <a href="javascript:;"
                   @click="$refs.table.del(record,{handlerName:'sbRetrunPaymentDeleteHandler'})">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <sbreturn-drawer ref="drawer" @success="onLoad"></sbreturn-drawer>
    <process-image ref="processImg" v-if="processImageVisible" :visible.sync="processImageVisible"
                   :processInstanceId="processInstanceId"></process-image>
  </div>
</template>
<script>
  import SbreturnDrawer from './sbreturn_drawer.vue'
  import api from './../js/api'
  import ProcessImage from '../../../flowable/process/process_image'


  export default {
    name: 'SbreturnEnd',
    components: {
      SbreturnDrawer,
      ProcessImage
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        processImageVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'left',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '票号',
            align: 'left',
            dataIndex: 'paymentNo'
          },
          {
            title: '供货商',
            align: 'left',
            dataIndex: 'supplierName'
          },
          {
            title: '收款账户',
            align: 'left',
            dataIndex: 'bankName'
          },
          {
            title: '退款金额',
            align: 'left',
            dataIndex: 'amount'
          },
          {
            title: '退款日期',
            align: 'left',
            dataIndex: 'payDate'
          },
          {
            title: '申请人',
            align: 'left',
            dataIndex: 'nickName'
          },
          {
            title: '退款状态',
            align: 'left',
            dataIndex: 'paymentState',
            scopedSlots: { customRender: 'paymentState' }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      //流程图
      processImg(order) {
        this.processInstanceId = order.processInstanceId
        this.processImageVisible = true
      },
      //重新提交
      completeTask(paymentId) {
        this.http.confirm(this, {
          content: '确认提交审批吗?',
          url: api.tasktodo.complete,
          requestBody: true,
          data: {
            taskId: paymentId.taskId
          },
          success: function(me, data) {
            me.$refs.table.refresh()
          }
        })
      },
      //提交审批
      startProcess(order) {
        this.http.confirm(this, {
          content: '确认提交审批吗?',
          url: api.processInstance.start,
          requestBody: true,
          data: {
            handlerName: 'paymentRefundStartProcessHandler',
            businessKey: order.paymentId
          },
          success: function(me, data) {
            me.$refs.table.refresh()
          }
        })
      },
      //刷新列表
      onLoad() {
        this.$refs.table.refresh()
      },
      //列表查询
      searchTable(searchParams) {
        searchParams.paymentState = 2
        this.queryParam = Object.assign(this.queryParam, searchParams)
        this.$refs.table.refresh(true, searchParams)
      }
    }
  }
</script>
